package feature;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ken
 * Date: 2023-11-26
 * Time: 19:17
 */
public class AddOperation implements IOPeration{
    @Override
    public void work(BookList bookList) {
        System.out.println("添加图书");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你要添加的书名");
        String name = scanner.nextLine();
        System.out.println("请输入这本书的作者");
        String author = scanner.nextLine();
        System.out.println("请输入这本书的价格");
        int price = scanner.nextInt();
        scanner.nextLine();
        System.out.println("请输入这本书的类型");
        String type = scanner.nextLine();
        Book book = new Book(name,author,price,type);
        int countsize = bookList.getUsedSize();
        for (int i = 0; i < countsize; i++) {
            Book temp = new BookList().getBooks(i);
            if(temp.getName().equals(name)) {
                System.out.println("已经有这本书了不能再放了");
                return;
            }
        }
        bookList.setBooks(book);
        bookList.setUsedSize(countsize+1);
    }
}
